/**
 * 
 */
package com.winit.openapi.mms.controller;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.common.spi.context.CommandContext;
import com.winit.erp.spi.bpartner.vo.Bpartner;
import com.winit.mms.spi.returns.ReturnMerchandiseService;
import com.winit.mms.spi.returns.command.QueryMerchandiseLikeCodeCommand;
import com.winit.mms.spi.v2.item.vo.ItemReturnVo;
import com.winit.openapi.constants.ApiConstant;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;

/**
 * 退货商品CONTROLLER
 * @author qibin.tang
 *
 */
@Controller
@RequestMapping(value = "/mms/returnMerchandise")
public class ReturnMerchandiseController extends BaseController {
	
	@Resource
	private ReturnMerchandiseService returnMerchandiseService;
    
    /**
     * 根据客户编码，商品编码模糊查询商品信息（不包含待维护退货商品商品，不包含已维护成原SKU的退货商品）
     * @param requestMsg
     * @param responseMsg
     * @return
     */
    @RequestMapping(value = "/queryProductLikeCode")
    public String queryProductLikeCode(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
    	Bpartner bpartner = CommandContext.getContext().get(ApiConstant.API_BPARTNER);
        Object obj = requestMsg.getData();
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            QueryMerchandiseLikeCodeCommand command = new QueryMerchandiseLikeCodeCommand();
            command.setSkuCode(json.getString("skuCode"));
            command.setCustomerCode(bpartner.getValue());
            List<ItemReturnVo> list = returnMerchandiseService.queryMerchandiseLikeCode(command);
            responseMsg.setData(list);
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        return SUCCESS;
    }
    
}
